local taling = fk.CreateSkill{
  name = "ls__taling",
}

Fk:loadTranslationTable{
  ["ls__taling"] = "踏凌",
  --[":ls__taling"] = "当你使用或打出【杀】后，你可行置“扬威”，然后令一名其他角色弃置装备区内的所有牌并失去1点体力；当你获得或弃置【杀】后，若“扬威”已行置，你可重置之。",
  [":ls__taling"] = "当你获得或失去【杀】后，你可展示所有手牌，若其中的【杀】数量为偶数/奇数，你令重置“扬威”的弃牌数-2/+2，然后令一名其他角色弃置一张牌/失去1点体力。",
  --["#ls__taling-reset"] = "踏凌：你可重置“扬威”",
  --["#ls__taling-choose"] = "踏凌：你可令一名角色弃置装备区内所有牌并失去1点体力",
  ["#ls__taling-discard"] = "踏凌：你可令一名其他角色弃置一张牌",
  ["#ls__taling-lose"] = "踏凌：你可令一名其他角色失去1点体力",

  ["$ls__taling1"] = "看见我的枪了吗？",
  ["$ls__taling2"] = "枪若白狼，一收一放。",
  ["$ls__taling3"] = "再持战枪，银芒乍亮。",
}

local DIY = require "packages/diy_utility/diy_utility"

taling:addEffect(fk.AfterCardsMove, {
  can_trigger = function(self, event, target, player, data)
    if player:isKongcheng() or not player:hasSkill(taling.name) then return end
    for _, move in ipairs(data) do
      if move.from == player then
        for _, info in ipairs(move.moveInfo) do
          return (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip) and Fk:getCardById(info.cardId).trueName == "slash"
        end
      elseif move.to == player and move.toArea == Card.PlayerHand then
        for _, info in ipairs(move.moveInfo) do
          return Fk:getCardById(info.cardId).trueName == "slash"
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:showCards(player:getCardIds("h"))
    local slashs = table.filter(player:getCardIds("h"), function (id)
      return Fk:getCardById(id).trueName == "slash"
    end)
    local prompt = ""
    if #slashs % 2 == 1 then
      prompt = "#ls__taling-lose"
      --DIY.changeReadyProgress(player, "ls__yangwei", -2, taling.name)
      DIY.setReadyCap(player, "ls__yangwei", DIY.getReadyCap(player, "ls__yangwei") + 2)
    elseif #slashs % 2 == 0 then
      prompt = "#ls__taling-discard"
      if DIY.getReadyCap(player, "ls__yangwei") <= 3 then
        DIY.changeReadyProgress(player, "ls__yangwei", 2, taling.name)
      else
        DIY.setReadyCap(player, "ls__yangwei", DIY.getReadyCap(player, "ls__yangwei") - 2)
      end
    end
    local n = DIY.getReadyCap(player, "ls__yangwei") - DIY.getReadyProgress(player, "ls__yangwei")
    player.room:setPlayerMark(player, "@ls__yangwei", n)
    local targets = room:getOtherPlayers(player)
    if #slashs % 2 == 0 then
      targets = table.filter(room:getOtherPlayers(player), function (p) return not p:isNude() end)
    end
    local to = room:askToChoosePlayers(player, {
      targets = targets,
      max_num = 1,
      min_num = 1,
      skill_name = taling.name,
      cancelable = true,
      prompt = prompt,
    })
    if #to > 0 then
      if prompt == "#ls__taling-lose" then
        room:loseHp(to[1], 1, taling.name)
      elseif prompt == "#ls__taling-discard" then
        room:askToDiscard(to[1], {
          min_num = 1,
          max_num = 1,
          include_equip = true,
          skill_name = taling.name,
          cancelable = false,
        })
      end
    end
  end,
})
--[[
taling:addEffect(fk.CardUseFinished, {
  audio_index = { 1, 2 },
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(taling.name) and target == player and data.card.trueName == "slash" and
    player:usedSkillTimes("ls__yangwei", Player.HistoryGame) == 0
  end,
  on_cost = function(self, event, target, player, data)
    local to = player.room:askToChoosePlayers(player, {
      skill_name = taling.name,
      targets = player.room:getOtherPlayers(player),
      min_num = 1,
      max_num = 1,
      prompt = "#ls__taling-choose",
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, {tos = to})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player:setSkillUseHistory("ls__yangwei", 1, Player.HistoryGame)
    local to = event:getCostData(self).tos[1]
    to:throwAllCards("e")
    if to:isAlive() then
      player.room:loseHp(to, 1, taling.name)
    end
  end,
})

taling:addEffect(fk.CardRespondFinished, {
  audio_index = { 1, 2 },
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(taling.name) and target == player and data.card.trueName == "slash" and
    player:usedSkillTimes("ls__yangwei", Player.HistoryGame) == 0
  end,
  on_cost = function(self, event, target, player, data)
    local to = player.room:askToChoosePlayers(player, {
      skill_name = taling.name,
      targets = player.room:getOtherPlayers(player),
      min_num = 1,
      max_num = 1,
      prompt = "#ls__taling-choose",
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, {tos = to})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player:setSkillUseHistory("ls__yangwei", 1, Player.HistoryGame)
    local to = event:getCostData(self).tos[1]
    to:throwAllCards("e")
    if to:isAlive() then
      player.room:loseHp(to, 1, taling.name)
    end
  end,
})

taling:addEffect(fk.AfterCardsMove, {
  audio_index = 3,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(taling.name) or player:usedSkillTimes("ls__yangwei", Player.HistoryGame) == 0 then return end
    for _, move in ipairs(data) do
      if (move.from == player and move.moveReason == fk.ReasonDiscard) or (move.to == player and move.toArea == Card.PlayerHand) then
        for _, info in ipairs(move.moveInfo) do
          return Fk:getCardById(info.cardId).trueName == "slash"
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, { skill_name = taling.name, prompt = "#ls__taling-reset" })
  end,
  on_use = function(self, event, target, player, data)
    player.room:sendLog{
      type = "#skill_reset",
      from = player.id,
      arg = "ls__yangwei",
      toast = true,
    }
    player:setSkillUseHistory("ls__yangwei", 0, Player.HistoryGame)
  end,
})
]]

return taling